package cn.csc.module.pay.controller.admin.jzb;

import cn.csc.framework.common.pojo.CommonResult;
import cn.csc.framework.jzb.core.JzbClient;
import cn.csc.framework.jzb.vo.JzbResponse;
import cn.csc.module.pay.controller.app.jzb.vo.CustAcctIdBalanceQueryReqVO;
import cn.csc.module.pay.enums.ErrorCodeConstants;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static cn.csc.framework.common.pojo.CommonResult.error;
import static cn.csc.framework.common.pojo.CommonResult.success;

/**
 * @author liuchuang
 * @version 1.0
 * @date 2024/3/29 17:52
 * @modify
 */
@Api(tags = "管理后台 - 见证宝业务")
@RestController
@RequestMapping("/pay/jzb")
@Validated
@Slf4j
@Setter
public class JzbController {

    @Autowired
    private JzbClient jzbClient;


    @PostMapping("/custAcctIdBalanceQuery")
    @ApiOperation(value = "查询银行子账户余额")
    public CommonResult<JzbResponse> custAcctIdBalanceQuery(@RequestBody CustAcctIdBalanceQueryReqVO reqVO) {
        JSONObject jsonObject = new JSONObject();
        //查询标志:2：普通会员子账号 3：功能子账号
        jsonObject.put("QueryFlag", reqVO.getQueryFlag());

        //见证子账户的账号(未启用)
        jsonObject.put("SubAcctNo", reqVO.getSubAcctNo());
        //页码:起始值为1，每次最多返回20条记录，第二页返回的记录数为第21至40条记录，第三页为41至60条记录，顺序均按照建立时间的先后
        jsonObject.put("PageNum", reqVO.getPageNum());

        //保留域
        jsonObject.put("ReservedMsg", "查询成功");

        JzbResponse response = jzbClient.send(jsonObject, "KFEJZB6010", "/V1.0/CustAcctIdBalanceQuery");
        log.info("KFEJZB6010(查询银行子账户余额)调用返回：{}", response.getData());
        if (response.isSuccess()) {
            return success(response);
        }
        return error(ErrorCodeConstants.CUST_ACCTID_BALANCE_QUERY_ERR, response);
    }


}
